#include "ksettingmanager.h"
#include <QDebug>
#include "ksettingutils.h"

KSettingManager KSettingManager::s_instance;


KSettingManager::KSettingManager()
	:m_settings(QSettings::NativeFormat,QSettings::UserScope,"Kingsoft","SvgEditor")
{

}

KSettingManager& KSettingManager::getInstance()
{
	return s_instance;
}

void KSettingManager::setLastShapeType(const KShapeType& type)
{
	QString shapeType = shapeTypeToString(type);

	m_settings.setValue("LastShapeType", shapeType);
}

QString KSettingManager::getLastShapeType() const
{
	return m_settings.value("LastShapeType", "Mouse").toString();
}

void KSettingManager::setViewSetting(const QString& key, const QVariant& value)
{
	m_settings.beginGroup("View");
	m_settings.setValue(key, value);
	m_settings.endGroup();
	qDebug() << "[Setting] setViewSetting:" << key << "=" << value;
}

QVariant KSettingManager::getViewSetting(const QString& key, const QVariant& defaultValue) const
{
	return m_settings.value("View/" + key, defaultValue);
}

void KSettingManager::setMainWindowSetting(const QString& key, const QVariant& value)
{
	m_settings.beginGroup("MainWindow");
	m_settings.setValue(key, value);
	m_settings.endGroup();
}

QVariant KSettingManager::getMainWindowSetting(const QString& key, const QVariant& defaultValue) const
{
	return m_settings.value("MainWindow/" + key, defaultValue);
}
